using System.IO;
using NUnit.Framework;
using Sedge.Core;
using Sedge.Core.App;
using Sedge.Core.Configuration;
using Sedge.Core.FileSystemWrap;

namespace Sedge.Tests.Configuration
{

    [TestFixture]
    public class SuiteRetrievingTest
    {
        private static Suite GetSuiteByName(string suiteName, bool complete)
        {
            string fullSuiteName = complete ? 
                TestUtils.GetCompleteDataFile(suiteName) : TestUtils.GetPartialDataFile(suiteName);

            SuiteFinderOptions finderOptions = new SuiteFinderOptions {SuiteFile = fullSuiteName};
            return SuiteFinder.GetSuite(finderOptions);
        }

        [SetUp]
        public void Setup()
        {
            // ReSharper disable PossibleNullReferenceException
            Services.StartupFolder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            // ReSharper restore PossibleNullReferenceException
        }

        [Test]
        public void GetEmptySuiteTest()
        {
            Services.FileSystem = new FileSystem();
            Suite suite = GetSuiteByName("emptySuite.sedge", true);
            Assert.IsNotNull(suite);
        }

        [Test]
        public void GetSuiteTest()
        {
            Services.FileSystem = new FileSystem();
            Suite suite = GetSuiteByName("default.sedge", true);
            Assert.IsNotNull(suite);
        }

        [Test]
        public void GetPartialSuiteTest()
        {
            Services.FileSystem = new FileSystem();
            Suite suite = GetSuiteByName("default.sedge", false);
            Assert.IsNotNull(suite);

            Assert.IsTrue(suite.Properties.ContainsKey("property.1"));
            Assert.IsTrue(suite.Properties.ContainsKey("property.2"));
				Assert.IsTrue(suite.Properties.ContainsKey("property.exists"));
				Assert.IsFalse(suite.Properties.ContainsKey("property.error"));
            Assert.IsTrue(suite.Applications.Count == 1);
        }
    }
}